package com.yiya.service;

import java.util.Date;
import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.yiya.bean.MaterialProcess;
import com.yiya.bean.SysUser;
import com.yiya.mapper.MaterialProcessMapper;
import com.yiya.model.MaterialProcessCplex;
import com.yiya.model.MaterialProcessCplexModel;

@Service("materialProcessService")
public class MaterialProcessService {
	@SuppressWarnings("unused")
	private final static Logger log = Logger.getLogger(MaterialProcessService.class);

	@Autowired
	private MaterialProcessMapper materialProcessMapper;
	
	public List<MaterialProcessCplex> queryByList(MaterialProcessCplexModel bean) {
		Integer rowCount = queryByCount(bean);
		bean.getPager().setRowCount(rowCount);
		List<MaterialProcessCplex> list = materialProcessMapper.selectByModel(bean);
		return list;
	}
	
	public int queryByCount(MaterialProcessCplexModel bean){
		return materialProcessMapper.countByModel(bean);
	}
	
	public int add(MaterialProcess bean){
		return materialProcessMapper.insert(bean);
	}
	
	public int Update(MaterialProcess bean){
		return materialProcessMapper.updateByPrimaryKeySelective(bean);
	}
	
	public MaterialProcess queryById(Integer id){
		return materialProcessMapper.selectByPrimaryKey(id);
	}
	
	public void delete(Integer[] ids,SysUser user){
		Date nowTime = new Date();
		for(Integer id:ids){
			MaterialProcess bean = materialProcessMapper.selectByPrimaryKey(id);
			bean.setUpdateBy(user.getId());
			bean.setUpdateTime(nowTime);
			bean.setDelFlag(1);
			materialProcessMapper.updateByPrimaryKeySelective(bean);
		}
	}

}
